﻿using System.Collections.Generic;

namespace Cms.Domain.Comparers
{
    public class ContentTranslationVersionComparer : IComparer<ContentTranslationVersion>
    {
        private readonly ContentTranslationVersionSortMode _mode;
        private readonly SortDirection _sortDirection;
        
        public ContentTranslationVersionComparer(SortDirection sortDirection, ContentTranslationVersionSortMode mode)
        {
            _sortDirection = sortDirection;
            _mode = mode;
        }

        #region IComparer<ContentTranslationVersion> Members

        public int Compare(ContentTranslationVersion x, ContentTranslationVersion y)
        {
            int result = 0;
            switch (_mode)
            {
                case ContentTranslationVersionSortMode.Timestamp:
                    result = string.Compare(x.Timestamp, y.Timestamp);
                    break;
            }
            return _sortDirection == SortDirection.Ascending ? result : result * -1;
        }

        #endregion
    }
}